package cn.melonlib.cores.commons.model.entity;

import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGenerationException;
import org.hibernate.id.IdentifierGenerator;

import java.io.Serializable;

public class CustomIdGenerator implements IdentifierGenerator {
    public Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException {
        if(object instanceof ICustomIdEntity) {
            return ((ICustomIdEntity<Serializable>) object).generatorId();
        }else {
            throw new IdentifierGenerationException("非自定义主键生成对象");
        }
    }
}
